package com.finger.fakegps.hook;

import de.robv.android.xposed.XSharedPreferences;

public class PreferencesUtils {

	private static XSharedPreferences.Editor mEditor = null;
	private static XSharedPreferences mSharedPreferences = null;

	private static XSharedPreferences getPreferences() {
		if (mSharedPreferences == null) {
			mSharedPreferences = new XSharedPreferences(PreferencesUtils.class.getPackage().getName());
			mSharedPreferences.makeWorldReadable();
		} else {
			mSharedPreferences.reload();
		}
		return mSharedPreferences;
	}

	public static void commitBoolean(String key, boolean value) {
		mEditor = getPreferences().edit();
		mEditor.putBoolean(key, value);
		mEditor.commit();
	}

	public static void commitInt(String key, int value) {
		mEditor = getPreferences().edit();
		mEditor.putInt(key, value);
		mEditor.commit();
	}

	public static void commitLong(String key, long value) {
		mEditor = getPreferences().edit();
		mEditor.putLong(key, value);
		mEditor.commit();
	}

	public static void commitString(String key, String value) {
		mEditor = getPreferences().edit();
		mEditor.putString(key, value);
		mEditor.commit();
	}

	public static Boolean getBoolean(String key, boolean defaultValue) {
		return Boolean.valueOf(getPreferences().getBoolean(key, defaultValue));
	}

	public static int getInt(String key, int defaultValue) {
		return getPreferences().getInt(key, defaultValue);
	}

	public static long getLong(String key, long defaultValue) {
		return getPreferences().getLong(key, defaultValue);
	}

	public static String getString(String key, String defaultValue) {
		return getPreferences().getString(key, defaultValue);
	}

	public static void removeAll() {
		mEditor = getPreferences().edit();
		mEditor.clear();
		mEditor.commit();
	}

	public static void removeKey(String paramString) {
		mEditor = getPreferences().edit();
		mEditor.remove(paramString);
		mEditor.commit();
	}
}
